package com.et.core.store

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

/**
 * table of advert
 * */
@Entity(tableName = "table_file")
data class FileEntity(
    @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") var uid: Int,
    @ColumnInfo(name = "file_name") var name: String,
    @ColumnInfo(name = "file_path") var filePath: String,
    @ColumnInfo(name = "file_url") var fileUrl: String,
    @ColumnInfo(name = "file_length") var fileLength: Long = 0L,
    @ColumnInfo(name = "file_status") var status: Int = STATUS_ENABLED,
) {
    companion object {
        const val MAX_DISABLED_TIMES = 3
        const val STATUS_ENABLED = Int.MAX_VALUE - 1
        const val STATUS_DISABLED = Int.MAX_VALUE - 2
        const val STATUS_DELETE = Int.MAX_VALUE - 3 // will delete file and database item
    }

    fun status() {
        if (status == STATUS_ENABLED) return
        if (status == STATUS_DISABLED) status = MAX_DISABLED_TIMES
        if (status < STATUS_DELETE) status--
        if (status < 0) status = STATUS_DELETE
    }

    override fun toString(): String {
        return "FileEntity(uid=$uid, name='$name', filePath='$filePath', fileUrl='$fileUrl', fileLength=$fileLength, status=$status)"
    }
}